package com.maychat.enums;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

@Getter
public enum ContactType {
    USER("U", "用户"),
    GROUP("G", "群组");
    private String prefix;
    private String desc;

    ContactType(String prefix, String desc) {
        this.prefix = prefix;
        this.desc = desc;
    }

    public static ContactType getByPrefix(String id) {
        if (StringUtils.isBlank(id)) return null;
        for (ContactType type : ContactType.values())
            if (id.startsWith(type.getPrefix())) return type;
        return null;
    }

    public static ContactType getByOrdinal(Integer ordinal) {
        ContactType[] values = values();
        if (ordinal == null || ordinal < 0 || ordinal >= values.length) return null;
        return values[ordinal];
    }

}
